class Solution {
public:
    unordered_map<int,int> has;
    int ret;
    void dfs(vector<int>& nums, int k,int cur)
    {
        if(cur>=nums.size())
        {
            ret++;
            return;
        }
        dfs(nums,k,cur+1);
        if(has[nums[cur]-k]==0 && has[nums[cur]+k]==0)
        {
            has[nums[cur]]++;
            dfs(nums,k,cur+1);
            has[nums[cur]]--;

        }
    }
    int beautifulSubsets(vector<int>& nums, int k) {
        
        dfs(nums,k,0);
        return ret-1;
    }
};
